package com.android.volley.components.volley;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

public class VolleyTool {
    private static VolleyTool mInstance = null;
    private RequestQueue mRequestQueue;
    private ImageLoader mImageLoader;
//    private Context context;

    private VolleyTool(Context context) {
        mRequestQueue = Volley.newRequestQueue(context);
    }

    public static VolleyTool getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new VolleyTool(context);
        }
//        mInstance.context = context;
        return mInstance;
    }

    public RequestQueue getmRequestQueue() {
        return mRequestQueue;
    }

    public ImageLoader getmImageLoader() {
        if (null == mImageLoader) {
            mImageLoader = new ImageLoader(mRequestQueue, BitmapCache.getBitmapCache());

//            mImageLoader = new ImageLoader(mRequestQueue, new DiskLruImageCache(context, context.getPackageCodePath(), Bitmap.CompressFormat.PNG));

        }
        return mImageLoader;
    }

    public void release() {
        this.mImageLoader = null;
        this.mRequestQueue = null;
        mInstance = null;
    }
}
